/**
 * 
 */
package ua.at.tsvetkov.application;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.os.StrictMode;

/**
 * Class wrapper for using StrictMode in all Android versions
 * @author Alexandr
 */
public class StrictModeWrapper {

	/**
	 * Using in onCreate() method in Application or Activity
	 * <pre>
	 * @code try {
	 * 	StrictModeWrapper.init(this)
	 * } catch (Throwable throwable) {
	 * 	Log.v("StrictMode", "StrictMode is not supported. Skipping...");
	 * }
	 * </pre>
	 * @param context
	 */
	public static void init(Context context) {
		int appFlags = context.getApplicationInfo().flags;
		if ((appFlags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
			StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
				.detectDiskReads()
				.detectDiskWrites()
				.detectNetwork()
				.penaltyLog()
				.build());
			StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
				.detectActivityLeaks()
				.detectLeakedSqlLiteObjects()
				.detectLeakedClosableObjects()
				.penaltyLog()
				.penaltyDeath()
				.build());
		}
	}

}
